<?php
/**
 * Created by PhpStorm.
 * User: yellow
 * Date: 2019/5/29
 * Time: 12:48
 */

namespace app\common\model;


use think\Model;

class BusSkd extends Model
{

    public function bus(){
        return $this->hasOne('bus', 'id', 'bus_id')->bind([
            'bus_no'
        ]);
    }

    public function business(){
        return $this->hasOne('BusBusiness', 'id', 'business_id')->bind([
            'business_name' => 'name'
        ]);
    }

    public function driver(){
        return $this->hasOne('BusDriver', 'id', 'driver_id')->bind([
            'driver_name' => 'name'
        ]);
    }

    public function getStatusAttr($value){
        $statusArr = ['未匹配', '匹配中', '已匹配'];
        return $statusArr[$value];
    }

    public function getSkdDateAttr($value){
        return date('Y-m-d', $value);
    }

    public function getEndDateAttr($value){
        return date('Y-m-d H:i:s', $value);
    }

    public function setSkdDateAttr($value){
        return strtotime($value);
    }

    public function setEndDateAttr($value){
        return strtotime($value);
    }

    public function setStatusAttr($value){
        if ($value){
            return 1;
        } else{
            return 0;
        }
    }

    public function getTypeAttr($value){
        $typeArr = [1=>'全天', 2=>'上午', 3=>'下午'];
        return $typeArr[$value];
    }

}